﻿using Stylet;
using System;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WinsionApp.Pages
{
    public class MainViewModel : Conductor<IScreen>.Collection.OneActive
    {
        /// <summary>
        /// 页面标题
        /// </summary>
        public string Title { get; set; } = "主界面";

        private readonly IViewFactory _viewFactory;

        public MainViewModel(IViewFactory viewFactory)
        {
            _viewFactory = viewFactory;
        }

        protected override void OnInitialActivate()
        {
            base.OnInitialActivate();
            InitMenuItemList();
        }

        public class MenuItem
        {
            public string Title { get; set; }
        }

        public List<MenuItem> MenuItemList { get; set; }
        public int SelectedIndex { get; set; } = 0;

        private void InitMenuItemList()
        {
            MenuItemList = new List<MenuItem>()
            {
                new MenuItem(){Title="测试模版"},
                new MenuItem(){Title="列表"},
                new MenuItem(){Title="报表(DataGird)"},
                
                //new MenuItem(){Title="Test"},
            };

            this.Bind(s => SelectedIndex, (o, e) => SelectedIndexChanged());
            SelectedIndexChanged();
        }

        private void SelectedIndexChanged()
        {
            switch (SelectedIndex)
            {
                case 0: ActivateItem(PageTestView ??= _viewFactory.PageTestViewModel()); break; 
                case 1: ActivateItem(PageListView ??= _viewFactory.PageListViewModel()); break; 
                case 2: ActivateItem(PageDataGridView ??= _viewFactory.PageDataGridViewModel()); break;
            }
        }


        private PageTestViewModel PageTestView;
        private PageListViewModel PageListView;
        private PageDataGridViewModel PageDataGridView;
    }
}
